package com.gitee.mapper;

import com.gitee.entity.Group;
import com.gitee.entity.User2Group;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface User2GroupMapper {
    @Insert("insert into user2group values(null, #{userId}, #{groupId})")
    void insert(User2Group user2Group);

    @Delete("delete from user2group where user_id = #{userId} and group_id = #{groupId}")
    void deleteByUserIdAndGroupId(User2Group user2Group);

    @Delete("delete from user2group where group_id = #{groupId}")
    void deleteByGroupId(Integer groupId);

    @Select("select * from user2group where group_id = #{groupId}")
    List<User2Group> selectByGroupId(Integer groupId);

    @Select("select * from user2group where group_id = #{groupId} and user_id = #{userId}")
    User2Group selectByGroupIdAndUserId(@Param("groupId") Integer groupId, @Param("userId") Integer userId);

    @Select("select * from user2group where user_id = #{userId}")
    List<User2Group> selectByUserId(Integer userId);
}
